<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-my.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-my.ico?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-my.ico?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="javascript,">





  <link rel="alternate" href="/atom.xml" title="徐子玉的笔记" type="application/atom+xml">






<meta name="description" content="这个utils.js主要用于layui中">
<meta name="keywords" content="javascript">
<meta property="og:type" content="article">
<meta property="og:title" content="前端工具函数utils.js">
<meta property="og:url" content="http://blog.xuziyu.cn/前端工具函数utils-js.html">
<meta property="og:site_name" content="徐子玉的笔记">
<meta property="og:description" content="这个utils.js主要用于layui中">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-03-16T07:34:33.693Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="前端工具函数utils.js">
<meta name="twitter:description" content="这个utils.js主要用于layui中">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '5.1.4',
    sidebar: {"position":"right","display":"always","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://blog.xuziyu.cn/前端工具函数utils-js.html">






  <title>前端工具函数utils.js | 徐子玉的笔记</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?b49e4132be4caecace2fcc27c6e8ec4d";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-right page-post-detail">
    <div class="headband"></div>
<a href="https://github.com/knight-peter" class="github-corner" aria-label="View source on Github"><svg width="80" height="80" viewbox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"/><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"/><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"/></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">徐子玉的笔记</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">Good Good Stady, Day Day Up.</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://blog.xuziyu.cn/前端工具函数utils-js.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="徐子玉">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="徐子玉的笔记">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">前端工具函数utils.js</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-10-24T14:44:00+08:00">
                2018-10-24
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/前端/" itemprop="url" rel="index">
                    <span itemprop="name">前端</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-comment-o"></i>
              </span>
              
                <a href="/前端工具函数utils-js.html#SOHUCS" itemprop="discussionUrl">
                  <span id="changyan_count_unit" class="post-comments-count hc-comment-count" data-xid="前端工具函数utils-js.html" itemprop="commentsCount"></span>
                </a>
              
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-eye" style="margin-right:7px;"></i>阅读次数
            <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>次
            </span>
          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  2,687 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  15 分钟
                </span>
              
            </div>
          

          

        </span></div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <blockquote>
<p>这个utils.js主要用于layui中<br><a id="more"></a></p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br><span class="line">359</span><br><span class="line">360</span><br><span class="line">361</span><br><span class="line">362</span><br><span class="line">363</span><br><span class="line">364</span><br><span class="line">365</span><br><span class="line">366</span><br><span class="line">367</span><br><span class="line">368</span><br><span class="line">369</span><br><span class="line">370</span><br><span class="line">371</span><br><span class="line">372</span><br><span class="line">373</span><br><span class="line">374</span><br><span class="line">375</span><br><span class="line">376</span><br><span class="line">377</span><br><span class="line">378</span><br><span class="line">379</span><br><span class="line">380</span><br><span class="line">381</span><br><span class="line">382</span><br><span class="line">383</span><br><span class="line">384</span><br><span class="line">385</span><br><span class="line">386</span><br><span class="line">387</span><br><span class="line">388</span><br><span class="line">389</span><br><span class="line">390</span><br><span class="line">391</span><br><span class="line">392</span><br><span class="line">393</span><br><span class="line">394</span><br><span class="line">395</span><br><span class="line">396</span><br><span class="line">397</span><br><span class="line">398</span><br><span class="line">399</span><br><span class="line">400</span><br><span class="line">401</span><br><span class="line">402</span><br><span class="line">403</span><br><span class="line">404</span><br><span class="line">405</span><br><span class="line">406</span><br><span class="line">407</span><br><span class="line">408</span><br><span class="line">409</span><br><span class="line">410</span><br><span class="line">411</span><br><span class="line">412</span><br><span class="line">413</span><br><span class="line">414</span><br><span class="line">415</span><br><span class="line">416</span><br><span class="line">417</span><br><span class="line">418</span><br><span class="line">419</span><br><span class="line">420</span><br><span class="line">421</span><br><span class="line">422</span><br><span class="line">423</span><br><span class="line">424</span><br><span class="line">425</span><br><span class="line">426</span><br><span class="line">427</span><br><span class="line">428</span><br><span class="line">429</span><br><span class="line">430</span><br><span class="line">431</span><br><span class="line">432</span><br><span class="line">433</span><br><span class="line">434</span><br><span class="line">435</span><br><span class="line">436</span><br><span class="line">437</span><br><span class="line">438</span><br><span class="line">439</span><br><span class="line">440</span><br><span class="line">441</span><br><span class="line">442</span><br><span class="line">443</span><br><span class="line">444</span><br><span class="line">445</span><br><span class="line">446</span><br><span class="line">447</span><br><span class="line">448</span><br><span class="line">449</span><br><span class="line">450</span><br><span class="line">451</span><br><span class="line">452</span><br><span class="line">453</span><br><span class="line">454</span><br><span class="line">455</span><br><span class="line">456</span><br><span class="line">457</span><br><span class="line">458</span><br><span class="line">459</span><br><span class="line">460</span><br><span class="line">461</span><br><span class="line">462</span><br><span class="line">463</span><br><span class="line">464</span><br><span class="line">465</span><br><span class="line">466</span><br><span class="line">467</span><br><span class="line">468</span><br><span class="line">469</span><br><span class="line">470</span><br><span class="line">471</span><br><span class="line">472</span><br><span class="line">473</span><br><span class="line">474</span><br><span class="line">475</span><br><span class="line">476</span><br><span class="line">477</span><br><span class="line">478</span><br><span class="line">479</span><br><span class="line">480</span><br><span class="line">481</span><br><span class="line">482</span><br><span class="line">483</span><br><span class="line">484</span><br><span class="line">485</span><br><span class="line">486</span><br><span class="line">487</span><br><span class="line">488</span><br><span class="line">489</span><br><span class="line">490</span><br><span class="line">491</span><br><span class="line">492</span><br><span class="line">493</span><br><span class="line">494</span><br><span class="line">495</span><br><span class="line">496</span><br><span class="line">497</span><br><span class="line">498</span><br><span class="line">499</span><br><span class="line">500</span><br><span class="line">501</span><br><span class="line">502</span><br><span class="line">503</span><br><span class="line">504</span><br><span class="line">505</span><br><span class="line">506</span><br><span class="line">507</span><br><span class="line">508</span><br><span class="line">509</span><br><span class="line">510</span><br><span class="line">511</span><br><span class="line">512</span><br><span class="line">513</span><br><span class="line">514</span><br><span class="line">515</span><br><span class="line">516</span><br><span class="line">517</span><br><span class="line">518</span><br><span class="line">519</span><br><span class="line">520</span><br><span class="line">521</span><br><span class="line">522</span><br><span class="line">523</span><br><span class="line">524</span><br><span class="line">525</span><br><span class="line">526</span><br><span class="line">527</span><br><span class="line">528</span><br><span class="line">529</span><br><span class="line">530</span><br><span class="line">531</span><br><span class="line">532</span><br><span class="line">533</span><br><span class="line">534</span><br><span class="line">535</span><br><span class="line">536</span><br></pre></td><td class="code"><pre><span class="line">/*</span><br><span class="line"> * 扩展一个utils模块</span><br><span class="line"> * */</span><br><span class="line">layui.define([&apos;layer&apos;, &apos;table&apos;, &apos;form&apos;, &apos;laydate&apos;, &apos;laytpl&apos;, &apos;admin&apos;, &apos;view&apos;], function (exports) &#123; //提示：模块也可以依赖其它模块，如：layui.define(&apos;layer&apos;, callback);</span><br><span class="line">  var $ = layui.$,</span><br><span class="line">    layer = layui.layer,</span><br><span class="line">    form = layui.form,</span><br><span class="line">    table = layui.table,</span><br><span class="line">    laydate = layui.laydate,</span><br><span class="line">    laytpl = layui.laytpl,</span><br><span class="line">    admin = layui.admin,</span><br><span class="line">    view = layui.view,</span><br><span class="line">    setter = layui.setter,</span><br><span class="line">    baseUrl = setter.baseUrl;</span><br><span class="line">  var utils = &#123;</span><br><span class="line">    // 测试</span><br><span class="line">    hello: function (str) &#123;</span><br><span class="line">      console.log(&apos;Hello &apos; + (str || &quot;xuqi&apos;s m-utils&quot;));</span><br><span class="line">    &#125;,</span><br><span class="line">    /*时间转换*/</span><br><span class="line">    checkTime: function checkTime(i) &#123;</span><br><span class="line">      if (i &lt; 10) &#123;</span><br><span class="line">        i = &apos;0&apos; + i;</span><br><span class="line">      &#125;</span><br><span class="line">      return i;</span><br><span class="line">    &#125;,</span><br><span class="line">    formatTime: function formatTime(date) &#123;</span><br><span class="line">      var getFullYear = this.checkTime(date.getFullYear());</span><br><span class="line">      var getMonth = this.checkTime(date.getMonth() + 1);</span><br><span class="line">      var getDate = this.checkTime(date.getDate());</span><br><span class="line">      var getHours = this.checkTime(date.getHours());</span><br><span class="line">      var getMinutes = this.checkTime(date.getMinutes());</span><br><span class="line">      var getSeconds = this.checkTime(date.getSeconds());</span><br><span class="line">      return getFullYear + &quot;-&quot; + getMonth + &quot;-&quot; + getDate + &quot; &quot; + getHours + &quot;:&quot; + getMinutes + &quot;:&quot; + getSeconds;</span><br><span class="line">    &#125;,</span><br><span class="line">    </span><br><span class="line">    /* 开发中的提示 */</span><br><span class="line">    coding: function (btn) &#123;</span><br><span class="line">      var btn_dom = btn;</span><br><span class="line">      if (!btn) &#123;</span><br><span class="line">        btn_dom = &apos;.js-btn-coding&apos;;</span><br><span class="line">      &#125;</span><br><span class="line">      $(btn_dom).on(&apos;click&apos;, function () &#123;</span><br><span class="line">        layer.alert(&apos;维护中，需官方授权开放&apos;);</span><br><span class="line">        return false;</span><br><span class="line">      &#125;);</span><br><span class="line">    &#125;,</span><br><span class="line">    codingAlert: function () &#123;</span><br><span class="line">      layer.alert(&apos;维护中，需官方授权开放&apos;);</span><br><span class="line">      return false;</span><br><span class="line">    &#125;,</span><br><span class="line">    /* 配置table */</span><br><span class="line">    setTableOption: function (dataName, method) &#123;</span><br><span class="line">      var method = method || &apos;get&apos;;</span><br><span class="line">      table.set(&#123;</span><br><span class="line">        method: method,</span><br><span class="line">        request: &#123;</span><br><span class="line">          pageName: &apos;curpage&apos;, //页码的参数名称，默认：page</span><br><span class="line">          limitName: &apos;pagesize&apos; //每页数据量的参数名，默认：limit</span><br><span class="line">        &#125;,</span><br><span class="line">        response: &#123;</span><br><span class="line">          statusName: &apos;code&apos;, //数据状态的字段名称，默认：code</span><br><span class="line">          statusCode: 200, //成功的状态码，默认：0</span><br><span class="line">          msgName: &apos;message&apos;, //状态信息的字段名称，默认：msg</span><br><span class="line">          countName: &apos;count&apos;, //数据总数的字段名称，默认：count</span><br><span class="line">          dataName: dataName //数据列表的字段名称，默认：data</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;)</span><br><span class="line">    &#125;,</span><br><span class="line">    /*类型验证*/</span><br><span class="line">    checkStr: function (str, type) &#123;</span><br><span class="line">      switch (type) &#123;</span><br><span class="line">        case &apos;phone&apos;:</span><br><span class="line">          //手机号码</span><br><span class="line">          return (/^1[3|4|5|7|8][0-9]&#123;9&#125;$/.test(str));</span><br><span class="line">        case &apos;tel&apos;:</span><br><span class="line">          //座机</span><br><span class="line">          return (/^(0\d&#123;2,3&#125;-\d&#123;7,8&#125;)(-\d&#123;1,4&#125;)?$/.test(str));</span><br><span class="line">        case &apos;card&apos;:</span><br><span class="line">          //身份证</span><br><span class="line">          return (/^\d&#123;15&#125;|\d&#123;18&#125;$/.test(str));</span><br><span class="line">        case &apos;pwd&apos;:</span><br><span class="line">          //密码以字母开头，长度在6~18之间，只能包含字母、数字和下划线</span><br><span class="line">          return (/^[a-zA-Z]\w&#123;5,17&#125;$/.test(str));</span><br><span class="line">        case &apos;postal&apos;:</span><br><span class="line">          //邮政编码</span><br><span class="line">          return (/[1-9]\d&#123;5&#125;(?!\d)/.test(str));</span><br><span class="line">        case &apos;QQ&apos;:</span><br><span class="line">          //QQ号</span><br><span class="line">          return (/^[1-9][0-9]&#123;4,9&#125;$/.test(str));</span><br><span class="line">        case &apos;email&apos;:</span><br><span class="line">          //邮箱</span><br><span class="line">          return (/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(str));</span><br><span class="line">        case &apos;money&apos;:</span><br><span class="line">          //金额(小数点2位)</span><br><span class="line">          return (/(^[1-9]([0-9]+)?(\.[0-9]&#123;1,2&#125;)?$)|(^(0)&#123;1&#125;$)|(^[0-9]\.[0-9]([0-9])?$)/.test(str)</span><br><span class="line">            // return (/^\d*(?:\.\d&#123;0,2&#125;)?$/.test(str)</span><br><span class="line">          );</span><br><span class="line">        case &apos;URL&apos;:</span><br><span class="line">          //网址</span><br><span class="line">          return (/(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?/.test(str));</span><br><span class="line">        case &apos;IP&apos;:</span><br><span class="line">          //IP</span><br><span class="line">          return (/((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.)&#123;3&#125;(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))/.test(str));</span><br><span class="line">        case &apos;date&apos;:</span><br><span class="line">          //日期时间</span><br><span class="line">          return (/^(\d&#123;4&#125;)\-(\d&#123;2&#125;)\-(\d&#123;2&#125;) (\d&#123;2&#125;)(?:\:\d&#123;2&#125;|:(\d&#123;2&#125;):(\d&#123;2&#125;))$/.test(str) || /^(\d&#123;4&#125;)\-(\d&#123;2&#125;)\-(\d&#123;2&#125;)$/.test(str));</span><br><span class="line">        case &apos;number&apos;:</span><br><span class="line">          //数字</span><br><span class="line">          return (/^[0-9]$/.test(str));</span><br><span class="line">        case &apos;integers&apos;:</span><br><span class="line">          //数字</span><br><span class="line">          return (/^-?[1-9]\d*$/.test(str));</span><br><span class="line">        case &apos;integer&apos;:</span><br><span class="line">          //非负整数</span><br><span class="line">          return (/^(0|[1-9]\d*)$/.test(str));</span><br><span class="line">        case &apos;integer5&apos;:</span><br><span class="line">          //非负整数1-5</span><br><span class="line">          return (/^[0-5]$/.test(str));</span><br><span class="line">        case &apos;english&apos;:</span><br><span class="line">          //英文</span><br><span class="line">          return (/^[a-zA-Z]+$/.test(str));</span><br><span class="line">        case &apos;chinese&apos;:</span><br><span class="line">          //中文</span><br><span class="line">          return (/^[\u4E00-\u9FA5]+$/.test(str));</span><br><span class="line">        case &apos;lower&apos;:</span><br><span class="line">          //小写</span><br><span class="line">          return (/^[a-z]+$/.test(str));</span><br><span class="line">        case &apos;upper&apos;:</span><br><span class="line">          //大写</span><br><span class="line">          return (/^[A-Z]+$/.test(str));</span><br><span class="line">        case &apos;HTML&apos;:</span><br><span class="line">          //HTML标记</span><br><span class="line">          return (/&lt;(&quot;[^&quot;]*&quot;|&apos;[^&apos;]*&apos;|[^&apos;&quot;&gt;])*&gt;/.test(str));</span><br><span class="line">        default:</span><br><span class="line">          return true;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    positiveInteger: function () &#123;</span><br><span class="line">      form.verify(&#123;</span><br><span class="line">        positiveInteger: [</span><br><span class="line">          /^(0|[1-9]\d*)$/, &apos;请输入正整数&apos;</span><br><span class="line">        ]</span><br><span class="line">      &#125;);</span><br><span class="line">    &#125;,</span><br><span class="line">    money: function () &#123;</span><br><span class="line">      form.verify(&#123;</span><br><span class="line">        money: [</span><br><span class="line">          /(^[1-9]([0-9]+)?(\.[0-9]&#123;1,2&#125;)?$)|(^(0)&#123;1&#125;$)|(^[0-9]\.[0-9]([0-9])?$)/, &apos;金额只能保留小数点后两位&apos;</span><br><span class="line">        ]</span><br><span class="line">      &#125;);</span><br><span class="line">    &#125;,</span><br><span class="line">    /*保留两位小数*/</span><br><span class="line">    returnFloat: function returnFloat(value) &#123;</span><br><span class="line">      // var value=Math.round(parseFloat(value)*100)/100;</span><br><span class="line">      var xsd = value.toString().split(&quot;.&quot;);</span><br><span class="line">      if (xsd.length == 1) &#123;</span><br><span class="line">        value = value.toString() + &quot;.00&quot;;</span><br><span class="line">        return value;</span><br><span class="line">      &#125;</span><br><span class="line">      if (xsd.length &gt; 1) &#123;</span><br><span class="line">        if (xsd[1].length &lt; 2) &#123;</span><br><span class="line">          value = value.toString() + &quot;0&quot;;</span><br><span class="line">        &#125; else &#123;</span><br><span class="line">          value = xsd[0] + &apos;.&apos; + xsd[1].substr(0, 2);</span><br><span class="line">        &#125;</span><br><span class="line">        return value;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    /*选择时间范围*/</span><br><span class="line">    laydate: function (dom) &#123;</span><br><span class="line">      laydate.render(&#123;</span><br><span class="line">        elem: dom, //指定元素</span><br><span class="line">        range: true, //或 range: &apos;~&apos; 来自定义分割字符</span><br><span class="line">        done: function (value, date, endDate) &#123;</span><br><span class="line">          var start_date, end_date;</span><br><span class="line">          var $start = $(dom).siblings(&apos;.js-time-start&apos;);</span><br><span class="line">          var $end = $(dom).siblings(&apos;.js-time-end&apos;);</span><br><span class="line">          // console.log(value);</span><br><span class="line">          if (value) &#123;</span><br><span class="line">            start_date = date.year + &apos;-&apos; + utils.checkTime(date.month) + &apos;-&apos; + utils.checkTime(date.date);</span><br><span class="line">            end_date = endDate.year + &apos;-&apos; + utils.checkTime(endDate.month) + &apos;-&apos; + utils.checkTime(endDate.date);</span><br><span class="line">          &#125; else &#123;</span><br><span class="line">            start_date = &apos;&apos;;</span><br><span class="line">            end_date = &apos;&apos;;</span><br><span class="line">          &#125;</span><br><span class="line">          console.log(&#123;</span><br><span class="line">            &apos;start_date&apos;: start_date,</span><br><span class="line">            &apos;end_date&apos;: end_date</span><br><span class="line">          &#125;);</span><br><span class="line">          $start.val(start_date);</span><br><span class="line">          $end.val(end_date);</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;);</span><br><span class="line">    &#125;,</span><br><span class="line">    /* 可能废弃，layer有photos方法可替换 */</span><br><span class="line">    showImg: function showImg($this, td_title_index) &#123;</span><br><span class="line">      let idx = td_title_index;</span><br><span class="line">      let type = typeof (idx);</span><br><span class="line">      // let this_id = &apos;#&apos; + $this.attr(&apos;id&apos;);</span><br><span class="line">      let this_class = &apos;.&apos; + $this.attr(&apos;class&apos;);</span><br><span class="line">      let td_img_index = $this.closest(&apos;td&apos;).index();</span><br><span class="line">      let th_img_title = $this.closest(&apos;.layui-table-box&apos;).find(&apos;.layui-table-header thead&gt;tr&gt;th&apos;).eq(td_img_index).text();</span><br><span class="line">      let content_img = $this.find(&apos;img&apos;);</span><br><span class="line">      let th_index_title = &apos;&apos;;</span><br><span class="line">      console.log(type)</span><br><span class="line">      if (idx &amp;&amp; type === &apos;number&apos;) &#123;</span><br><span class="line">        th_index_title = $this.closest(&apos;tr&apos;).find(&apos;td&apos;).eq(idx).text();</span><br><span class="line">        th_img_title = th_index_title + &apos;的&apos; + th_img_title;</span><br><span class="line">      &#125; else if (idx &amp;&amp; type === &apos;string&apos;) &#123;</span><br><span class="line">        th_index_title = $this.closest(&apos;tr&apos;).find(&apos;td[data-field=&quot;&apos; + idx + &apos;&quot;]&apos;).text();</span><br><span class="line">        th_img_title = th_index_title + &apos;的&apos; + th_img_title;</span><br><span class="line">      &#125;</span><br><span class="line">      // console.log(idx, this_str);</span><br><span class="line">      layer.open(&#123;</span><br><span class="line">        type: 1,</span><br><span class="line">        shadeClose: true,</span><br><span class="line">        scrollbar: false,</span><br><span class="line">        title: th_img_title || &apos;图像&apos;,</span><br><span class="line">        content: $this, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响</span><br><span class="line">        // area: [&apos;500px&apos;, &apos;542px&apos;],</span><br><span class="line">        success: function () &#123;</span><br><span class="line">          $(&apos;body&apos;).off(&apos;click&apos;, this_class);</span><br><span class="line">        &#125;,</span><br><span class="line">        end: function () &#123;</span><br><span class="line">          $(&apos;body&apos;).on(&apos;click&apos;, this_class, function () &#123;</span><br><span class="line">            var $this = $(this);</span><br><span class="line">            console.log(idx);</span><br><span class="line">            utils.showImg($this, idx);</span><br><span class="line">          &#125;);</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;);</span><br><span class="line">    &#125;,</span><br><span class="line">    /*展示图片新方法*/</span><br><span class="line">    photos: function (domClass) &#123;</span><br><span class="line">      var imgParent = $(&apos;img&apos;).parent();</span><br><span class="line">      if (domClass) &#123;</span><br><span class="line">        imgParent = $(`.$&#123;domClass&#125;`);</span><br><span class="line">      &#125;</span><br><span class="line">      imgParent.each(function (i) &#123;</span><br><span class="line">        let id = $(this).attr(&apos;id&apos;);</span><br><span class="line">        if (id) &#123;</span><br><span class="line">          layer.photos(&#123;</span><br><span class="line">            photos: `#$&#123;id&#125;`,</span><br><span class="line">            anim: 5</span><br><span class="line">          &#125;)</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;);</span><br><span class="line">    &#125;,</span><br><span class="line">    /* 关闭layer的iframe窗口 */</span><br><span class="line">    closeIframe: function () &#123;</span><br><span class="line">      var index = parent.layer.getFrameIndex(window.name);</span><br><span class="line">      parent.layer.close(index)</span><br><span class="line">    &#125;,</span><br><span class="line">    /* 获取url参数，返回值为object */</span><br><span class="line">    args: function (params) &#123;</span><br><span class="line">      var a = &#123;&#125;;</span><br><span class="line">      params = params || location.search;</span><br><span class="line">      if (!params) return &#123;&#125;;</span><br><span class="line">      params = decodeURI(params);</span><br><span class="line">      params.replace(/(?:^\?|&amp;)([^=&amp;]+)(?:\=)([^=&amp;]+)(?=&amp;|$)/g, function (m, k, v) &#123;</span><br><span class="line">        a[k] = v;</span><br><span class="line">      &#125;);</span><br><span class="line">      return a;</span><br><span class="line">    &#125;,</span><br><span class="line">    /* 重置form表单方法，不会重置部分input的值 */</span><br><span class="line">    reset: function ($reset) &#123;</span><br><span class="line">      var $input = $($reset).closest(&apos;.layui-form&apos;).find(&quot;:input&quot;);</span><br><span class="line">      // var $select = $($reset).closest(&apos;.layui-form&apos;).find(&quot;select&quot;);</span><br><span class="line">      // console.log($input.not(&quot;:button, :submit, :reset,:disabled,[readonly]&quot;));</span><br><span class="line">      $input.not(&quot;:button, :submit, :reset,:disabled,[readonly]&quot;).val(&quot;&quot;);</span><br><span class="line">      $input.not(&quot;:disabled,[readonly]&quot;).removeAttr(&quot;checked&quot;);</span><br><span class="line">    &#125;,</span><br><span class="line">    /*模板渲染*/</span><br><span class="line">    tplRender: function (tplId, viewId, tplData, callback) &#123;</span><br><span class="line">      var $tplId, $viewId;</span><br><span class="line">      if (typeof (tplId) === &apos;string&apos;) &#123;</span><br><span class="line">        if (tplId.indexOf(&apos;#&apos;) === -1) &#123;</span><br><span class="line">          $tplId = document.getElementById(tplId);</span><br><span class="line">        &#125; else &#123;</span><br><span class="line">          $tplId = document.getElementById(tplId.substring(1));</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">      if (typeof (viewId) === &apos;string&apos;) &#123;</span><br><span class="line">        if (viewId.indexOf(&apos;#&apos;) === -1) &#123;</span><br><span class="line">          $viewId = document.getElementById(viewId);</span><br><span class="line">        &#125; else &#123;</span><br><span class="line">          $viewId = document.getElementById(viewId.substring(1));</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">      var getTpl, view;</span><br><span class="line">      if ($tplId) &#123;</span><br><span class="line">        getTpl = $tplId.innerHTML;</span><br><span class="line">      &#125; else &#123;</span><br><span class="line">        getTpl = tplId.innerHTML;</span><br><span class="line">      &#125;</span><br><span class="line">      if ($viewId) &#123;</span><br><span class="line">        view = $viewId;</span><br><span class="line">      &#125; else &#123;</span><br><span class="line">        view = viewId;</span><br><span class="line">      &#125;</span><br><span class="line">      var data = tplData || true;</span><br><span class="line">      // console.log(data)</span><br><span class="line">      laytpl(getTpl).render(</span><br><span class="line">        data,</span><br><span class="line">        function (html) &#123;</span><br><span class="line">          view.innerHTML = html;</span><br><span class="line">          callback &amp;&amp; callback();</span><br><span class="line">        &#125;</span><br><span class="line">      );</span><br><span class="line"></span><br><span class="line">    &#125;,</span><br><span class="line">    /* 给没有http开头的图片修改成完整的图片地址 */</span><br><span class="line">    ossUrl: &apos;http://garment-scm.oss-cn-hangzhou.aliyuncs.com/&apos;,</span><br><span class="line">    imgUrl: function (img, size, url) &#123;</span><br><span class="line">      let newUrl = img;</span><br><span class="line">      let baseUrl = url || this.ossUrl;</span><br><span class="line">      let urlAfter = size || &apos;&apos;;</span><br><span class="line">      if (size === &apos;sm&apos;) &#123;</span><br><span class="line">        urlAfter = &apos;?x-oss-process=image/resize,w_132,h_132&apos;;</span><br><span class="line">      &#125;</span><br><span class="line">      if (size === &apos;lg&apos;) &#123;</span><br><span class="line">        urlAfter = &apos;?x-oss-process=image/resize,w_800,h_800&apos;;</span><br><span class="line">      &#125;</span><br><span class="line">      if (img.indexOf(&apos;http&apos;) === -1) &#123;</span><br><span class="line">        // newUrl=baseUrl+newUrl;</span><br><span class="line">        newUrl = baseUrl + newUrl + urlAfter;</span><br><span class="line">      &#125;</span><br><span class="line">      return newUrl;</span><br><span class="line">    &#125;,</span><br><span class="line">    /* 给没有http开头的网址添加成完整的网址 */</span><br><span class="line">    httpUrl: function (url) &#123;</span><br><span class="line">      let newUrl = url;</span><br><span class="line">      if (url.indexOf(&apos;http&apos;) === -1) &#123;</span><br><span class="line">        newUrl = &apos;http://&apos; + newUrl;</span><br><span class="line">      &#125;</span><br><span class="line">      return newUrl;</span><br><span class="line">    &#125;,</span><br><span class="line">    strSubstr(str, index) &#123;</span><br><span class="line">      let num = this.ossUrl.length;</span><br><span class="line">      let idx = index || 0;</span><br><span class="line">      let newStr = str.substr(idx, num)</span><br><span class="line">    &#125;,</span><br><span class="line">    /* 把图片名称组成的字符串转换成数组Array */</span><br><span class="line">    strToArr: function (str, separator) &#123;</span><br><span class="line">      var splitStr = separator || &apos;|&apos;;</span><br><span class="line">      var Arr = [];</span><br><span class="line">      if (str) &#123;</span><br><span class="line">        Arr = str.split(splitStr)</span><br><span class="line">      &#125;</span><br><span class="line">      return Arr;</span><br><span class="line">    &#125;,</span><br><span class="line">    /* 把图片名称组成的数组Array转换成字符串String */</span><br><span class="line">    arrToStr: function (arr, separator) &#123;</span><br><span class="line">      var splitStr = separator || &apos;|&apos;;</span><br><span class="line">      var Str = arr.join(splitStr);</span><br><span class="line">      if (arr.length === 1) &#123;</span><br><span class="line">        Str = arr[0]</span><br><span class="line">      &#125;</span><br><span class="line">      if (arr.length === 0) &#123;</span><br><span class="line">        Str = &apos;&apos;</span><br><span class="line">      &#125;</span><br><span class="line">      return Str;</span><br><span class="line">    &#125;,</span><br><span class="line">    /*数组去重*/</span><br><span class="line">    arrNoRep: function (arr) &#123;</span><br><span class="line">      for (var i = 0; i &lt; arr.length; i++) &#123;</span><br><span class="line">        if (arr.indexOf(arr[i]) != i) &#123;</span><br><span class="line">          arr.splice(i, 1);//删除数组元素后数组长度减1后面的元素前移</span><br><span class="line">          i--;//数组下标回退</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">      return arr;</span><br><span class="line">    &#125;,</span><br><span class="line">    /*数组相减*/</span><br><span class="line">    arrMinus: function (a, b) &#123;</span><br><span class="line">      let lg=[],sm=[];</span><br><span class="line">      if(a.length&gt;=b.length)&#123;</span><br><span class="line">        lg=a.concat();</span><br><span class="line">        sm=b.concat();</span><br><span class="line">      &#125;else&#123;</span><br><span class="line">        lg=b.concat();</span><br><span class="line">        sm=a.concat();</span><br><span class="line">      &#125;</span><br><span class="line">      // console.log(lg,sm)</span><br><span class="line">      for (var i = lg.length - 1; i &gt;= 0; i--) &#123;</span><br><span class="line">        a = lg[i];</span><br><span class="line">        for (var j = sm.length - 1; j &gt;= 0; j--) &#123;</span><br><span class="line">          b = sm[j];</span><br><span class="line">          if (a == b) &#123;</span><br><span class="line">            lg.splice(i, 1);</span><br><span class="line">            sm.splice(j, 1);</span><br><span class="line">            break;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">      return lg;</span><br><span class="line">    &#125;,</span><br><span class="line">    /*添加图片*/</span><br><span class="line">    _addItimImg: function (&#123;elemId, hiddenId, list, picture, one = true&#125;) &#123;</span><br><span class="line">      let that = this;</span><br><span class="line">      // console.log(&apos;_addItimImg:&apos;,$(hiddenId).val());</span><br><span class="line">      let valArr = utils.strToArr($(hiddenId).val());</span><br><span class="line"></span><br><span class="line">      valArr[valArr.length] = picture;</span><br><span class="line">      let valNew = utils.arrToStr(valArr);</span><br><span class="line">      let $list = $(elemId).closest(&apos;.js-upload-group&apos;).find(list);</span><br><span class="line"></span><br><span class="line">      let newId = &apos;id&apos; + (new Date().getTime());</span><br><span class="line">      let $item = `&lt;div class=&quot;layui-upload-item&quot;&gt;</span><br><span class="line">                      &lt;div class=&quot;layui-upload-item__child&quot; id=&quot;$&#123;newId&#125;&quot;&gt;</span><br><span class="line">                      &lt;img layer-src=&quot;$&#123;this.imgUrl(picture)&#125;&quot; src=&quot;$&#123;this.imgUrl(picture)&#125;&quot;&gt;</span><br><span class="line">                      &lt;/div&gt;</span><br><span class="line">                      &lt;a href=&quot;javascript:;&quot; class=&quot;layui-upload-img-del js-upload-img-del&quot;&gt;删除&lt;/a&gt;</span><br><span class="line">                    &lt;/div&gt;`;</span><br><span class="line">      if (one) &#123;</span><br><span class="line">        $list.html($item);</span><br><span class="line">        valNew = picture</span><br><span class="line">      &#125; else &#123;</span><br><span class="line">        $list.append($item);</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line">      $(hiddenId).val(valNew);</span><br><span class="line">      layer.msg(&apos;上传成功&apos;, &#123;</span><br><span class="line">        icon: 1,</span><br><span class="line">        time: 800</span><br><span class="line">      &#125;, function () &#123;</span><br><span class="line">        that.photos();</span><br><span class="line">      &#125;);</span><br><span class="line">    &#125;,</span><br><span class="line">    /*删除图片列表中的图片*/</span><br><span class="line">    _delItemImg: function (&#123;$this, hiddenId, item&#125;) &#123;</span><br><span class="line">      let that = this;</span><br><span class="line">      // const itemId = $($this).closest(item).attr(&apos;id&apos;);</span><br><span class="line">      layer.confirm(&apos;确定要删除该图片吗？&apos;, &#123;</span><br><span class="line">        icon: 2</span><br><span class="line">      &#125;, function (index) &#123;</span><br><span class="line">        layer.close(index);</span><br><span class="line">        let thisFullSrc = $($this).closest(item).find(&apos;img&apos;).attr(&apos;src&apos;);</span><br><span class="line">        console.log(thisFullSrc)</span><br><span class="line">        let thisSrc = utils.strSubstr(thisFullSrc);</span><br><span class="line">        let imgStr = $(hiddenId).val();</span><br><span class="line">        let imgArr = utils.strToArr(imgStr);</span><br><span class="line">        let arrIndex = $.inArray(thisSrc, imgArr);</span><br><span class="line">        imgArr.splice(arrIndex, 1);</span><br><span class="line">        let newImgStr = utils.arrToStr(imgArr);</span><br><span class="line">        $(hiddenId).val(newImgStr)</span><br><span class="line">        $($this).closest(item).remove();</span><br><span class="line">      &#125;)</span><br><span class="line">    &#125;,</span><br><span class="line">    /*自定义input验证*/</span><br><span class="line">    verify: function () &#123;</span><br><span class="line">      form.verify(&#123;</span><br><span class="line">        nickname: function (value, item) &#123; //value：表单的值、item：表单的DOM对象</span><br><span class="line">          if (!new RegExp(&quot;^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$&quot;).test(value)) &#123;</span><br><span class="line">            return &apos;用户名不能有特殊字符&apos;;</span><br><span class="line">          &#125;</span><br><span class="line">          if (/(^\_)|(\__)|(\_+$)/.test(value)) &#123;</span><br><span class="line">            return &apos;用户名首尾不能出现下划线\&apos;_\&apos;&apos;;</span><br><span class="line">          &#125;</span><br><span class="line">          if (/^\d+\d+\d$/.test(value)) &#123;</span><br><span class="line">            return &apos;用户名不能全为数字&apos;;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        //我们既支持上述函数式的方式，也支持下述数组的形式</span><br><span class="line">        //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]</span><br><span class="line">        ,</span><br><span class="line">        pass: [</span><br><span class="line">          /^[\S]&#123;6,12&#125;$/, &apos;密码必须6到12位，且不能出现空格&apos;</span><br><span class="line">        ]</span><br><span class="line"></span><br><span class="line">        //确认密码</span><br><span class="line">        ,</span><br><span class="line">        repass: function (value) &#123;</span><br><span class="line">          if (value !== $(&apos;#newPassword&apos;).val()) &#123;</span><br><span class="line">            return &apos;两次密码输入不一致&apos;;</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;,</span><br><span class="line">        positiveInteger: [</span><br><span class="line">          /^(0|[1-9]\d*)$/, &apos;请输入正整数&apos;</span><br><span class="line">        ],</span><br><span class="line">        money: [</span><br><span class="line">          /(^[1-9]([0-9]+)?(\.[0-9]&#123;1,2&#125;)?$)|(^(0)&#123;1&#125;$)|(^[0-9]\.[0-9]([0-9])?$)/, &apos;金额只能保留小数点后两位&apos;</span><br><span class="line">        ]</span><br><span class="line">      &#125;);</span><br><span class="line">    &#125;,</span><br><span class="line">    /* 过滤掉formData的空值 */</span><br><span class="line">    formDataFilter: function (object) &#123;</span><br><span class="line">      for (key in object) &#123;</span><br><span class="line">        if (object[key] === &apos;&apos;) &#123;</span><br><span class="line">          delete object[key]</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;</span><br><span class="line">      return object</span><br><span class="line">    &#125;,</span><br><span class="line">    /* 获取table数据,在回调函数callback里渲染table */</span><br><span class="line">    tableReq: function (options) &#123;</span><br><span class="line">      let formData = options.formData,</span><br><span class="line">        url = `$&#123;baseUrl&#125;$&#123;options.url&#125;`,</span><br><span class="line">        type = options.type || &apos;GET&apos;,</span><br><span class="line">        dataType = options.dataType || &apos;json&apos;,</span><br><span class="line">        data = this.formDataFilter(options.data),</span><br><span class="line">        callback = options.callback;</span><br><span class="line">      admin.req(&#123;</span><br><span class="line">        url: url,</span><br><span class="line">        type: type,</span><br><span class="line">        dataType: dataType,</span><br><span class="line">        data: data,</span><br><span class="line">        done: function (res) &#123;</span><br><span class="line">          callback &amp;&amp; callback(res);</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;)</span><br><span class="line">    &#125;,</span><br><span class="line">    /* 判断小屏，弹出层全屏 */</span><br><span class="line">    full: function (layerName) &#123;</span><br><span class="line">      let screenNum = admin.screen();</span><br><span class="line">      if (screenNum === 0) &#123;</span><br><span class="line">        layer.full(layerName);</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;;</span><br><span class="line"></span><br><span class="line">  /* 清空form数据 */</span><br><span class="line"></span><br><span class="line">  var $dateRest = $(&apos;.layui-form [type=&quot;reset&quot;]&apos;);</span><br><span class="line"></span><br><span class="line">  $($dateRest).on(&apos;click&apos;, function () &#123;</span><br><span class="line">    utils.reset($(this));</span><br><span class="line">    form.render();</span><br><span class="line">    return false;</span><br><span class="line">  &#125;);</span><br><span class="line"></span><br><span class="line">  // 输出test接口</span><br><span class="line">  exports(&apos;utils&apos;, utils);</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
      
    </div>
    
    
    

    
      <div>
        <div id="wechat_subscriber" style="display: block; padding: 10px 0; margin: 20px auto; width: 100%; text-align: center">
    <img id="wechat_subscriber_qcode" src="/uploads/wechat-qcode.jpg" alt="徐子玉 wechat" style="width: 200px; max-width: 100%;">
    <div>欢迎您扫一扫上面的微信二维码，订阅我的公众号！</div>
</div>

      </div>
    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechat-reward.gif" alt="徐子玉 微信支付">
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay-reward.gif" alt="徐子玉 支付宝">
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/javascript/" <i class="fa fa-tag"> javascript</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/测试七牛云图片.html" rel="next" title="测试七牛云图片">
                <i class="fa fa-chevron-left"></i> 测试七牛云图片
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="SOHUCS"></div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/avatar.jpg" alt="徐子玉">
            
              <p class="site-author-name" itemprop="name">徐子玉</p>
              <p class="site-description motion-element" itemprop="description">喜欢跑步的吃货才是一个好程序猿</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">18</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">4</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">15</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/knight-peter" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:xuqipeter@qq.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-inline">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                友情链接
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.imooc.com" title="慕课网" target="_blank" rel="external nofollow">慕课网</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.liaoxuefeng.com/" title="廖雪峰的官方网站" target="_blank" rel="external nofollow">廖雪峰的官方网站</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2018 &mdash; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">徐子玉</span>

  
</div>

<!--

  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io" rel="external nofollow">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next" rel="external nofollow">NexT.Mist</a> v5.1.4</div>

-->

<p>Hosted by <a href="https://pages.coding.me" style="font-weight: bold">Coding Pages</a></p>
        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i> 本站访客数
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      人
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i> 本站总访问量
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      次
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  




  
    <script type="text/javascript">
    (function(){
      var appid = 'cytsHS66l';
      var conf = 'e2a8af2f881183b9aa2cdfcaa43bf747';
      var width = window.innerWidth || document.documentElement.clientWidth;
      if (width < 960) {
      window.document.write('<script id="changyan_mobile_js" charset="utf-8" type="text/javascript" src="https://changyan.sohu.com/upload/mobile/wap-js/changyan_mobile.js?client_id=' + appid + '&conf=' + conf + '"><\/script>'); } else { var loadJs=function(d,a){var c=document.getElementsByTagName("head")[0]||document.head||document.documentElement;var b=document.createElement("script");b.setAttribute("type","text/javascript");b.setAttribute("charset","UTF-8");b.setAttribute("src",d);if(typeof a==="function"){if(window.attachEvent){b.onreadystatechange=function(){var e=b.readyState;if(e==="loaded"||e==="complete"){b.onreadystatechange=null;a()}}}else{b.onload=a}}c.appendChild(b)};loadJs("https://changyan.sohu.com/upload/changyan.js",function(){
        window.changyan.api.config({appid:appid,conf:conf})});
      }
    })();
    </script>
    <script type="text/javascript" src="https://assets.changyan.sohu.com/upload/plugins/plugins.count.js"></script>
  









  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  
  

  

  

  

</body>
</html>
